package com.studyroom.mapper;

import com.baomidou.mybatisplus.annotation.IdType;
import com.studyroom.entity.Icon;
import com.studyroom.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 
 * @since 2022-11-21
 */
public interface UserMapper extends BaseMapper<User> {
    @Select ("select u.* from user_relation r join user u on r.contact_id=u.id where r.user_id=${id} ")
    List<User> getUsersByUserIdWithUserRelation(Long id);
    @Insert ("insert into user_relation(user_id,contact_id,relation_key) values(${userId},${contactId},${relationKey})")
    void saveUserRelation(Long userId,Long contactId,Long relationKey);
    @Select ("select u.* from user_relation r join user u on r.contact_id=u.id where r.user_id=${mineId} and r.contact_id=${id}")
    User getUserByUserRealtion(Long mineId,Long id);
    @Select("select * from icon")
    List<Icon> getIcons();
    @Select ("select relation_key from user_relation where user_id=${userId} and contact_id=${contactId}")
    public Long getUserRelationKey(Long userId,Long contactId);
}
